// 简化的OSS上传实现，避免类型问题
export interface UploadProgress {
  loaded: number
  total: number
  percent: number
}
export interface UploadResult {
  url: string
  name: string
  size: number
}
export interface UploadOptions {
  onProgress?: (progress: UploadProgress) => void
  onSuccess?: (result: UploadResult) => void
  onError?: (error: Error) => void
}
// 模拟OSS上传功能（实际项目中需要替换为真实的OSS上传）
export const uploadFile = async (
  file: File, 
  options: UploadOptions = {}
): Promise<UploadResult> => {
  return new Promise((resolve, reject) => {
    // 模拟上传进度
    let progress = 0
    const interval = setInterval(() => {
      progress += Math.random() * 20
      if (progress >= 100) {
        progress = 100
        clearInterval(interval)
        // 模拟上传成功 - 使用本地预览URL
        const result: UploadResult = {
          url: URL.createObjectURL(file), // 使用本地预览URL
          name: file.name,
          size: file.size
        }
        if (options.onProgress) {
          options.onProgress({
            loaded: file.size,
            total: file.size,
            percent: 100
          })
        }
        if (options.onSuccess) {
          options.onSuccess(result)
        }
        resolve(result)
      } else {
        if (options.onProgress) {
          options.onProgress({
            loaded: Math.round((progress / 100) * file.size),
            total: file.size,
            percent: Math.round(progress)
          })
        }
      }
    }, 200)
    // 模拟可能的错误
    if (Math.random() < 0.1) { // 10% 概率失败
      clearInterval(interval)
      const error = new Error('模拟上传失败')
      if (options.onError) {
        options.onError(error)
      }
      reject(error)
    }
  })
}
// 批量上传
export const uploadMultipleFiles = async (
  files: File[], 
  options: UploadOptions = {}
): Promise<UploadResult[]> => {
  const results: UploadResult[] = []
  for (const file of files) {
    try {
      const result = await uploadFile(file, options)
      results.push(result)
    } catch (error) {
      console.error('文件上传失败:', file.name, error)
    }
  }
  return results
}
// 删除文件（模拟）
export const deleteFile = async (fileName: string): Promise<void> => {
  console.log('删除文件:', fileName)
  // 实际项目中这里应该调用OSS的删除API
}